package com.jsh.erp.service.cheque;

import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.service.ICommonQuery;
import com.jsh.erp.utils.Constants;
import com.jsh.erp.utils.QueryUtils;
import com.jsh.erp.utils.StringUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Service(value = "cheque_component")
@ChequeResource
public class ChequeComponent implements ICommonQuery {

    @Resource
    private ChequeService chequeService;

    @Override
    public Object selectOne(Long id) throws Exception {
        return chequeService.getById(id);
    }

    @Override
    public List<?> select(Map<String, String> map) throws Exception {
        String search = map.get(Constants.SEARCH);
        String chequeNumber = StringUtil.getInfo(search, "chequeNumber");
        String beginTime = StringUtil.getInfo(search, "beginTime");
        String endTime = StringUtil.getInfo(search, "endTime");
        Long organId = StringUtil.parseStrLong(StringUtil.getInfo(search, "organId"));
        Long creator = StringUtil.parseStrLong(StringUtil.getInfo(search, "creator"));
        Long handsPersonId = StringUtil.parseStrLong(StringUtil.getInfo(search, "handsPersonId"));
        Long accountId = StringUtil.parseStrLong(StringUtil.getInfo(search, "accountId"));
        String status = StringUtil.getInfo(search, "status");
        String remark = StringUtil.getInfo(search, "remark");
        return chequeService.select(chequeNumber, beginTime, endTime, organId, creator,
                handsPersonId, accountId, status, remark, QueryUtils.offset(map), QueryUtils.rows(map));
    }

    @Override
    public Long counts(Map<String, String> map) throws Exception {
        String search = map.get(Constants.SEARCH);
        String chequeNumber = StringUtil.getInfo(search, "chequeNumber");
        String beginTime = StringUtil.getInfo(search, "beginTime");
        String endTime = StringUtil.getInfo(search, "endTime");
        Long organId = StringUtil.parseStrLong(StringUtil.getInfo(search, "organId"));
        Long creator = StringUtil.parseStrLong(StringUtil.getInfo(search, "creator"));
        Long handsPersonId = StringUtil.parseStrLong(StringUtil.getInfo(search, "handsPersonId"));
        Long accountId = StringUtil.parseStrLong(StringUtil.getInfo(search, "accountId"));
        String status = StringUtil.getInfo(search, "status");
        String remark = StringUtil.getInfo(search, "remark");
        return chequeService.countCheque(chequeNumber, beginTime, endTime, organId, creator,
                handsPersonId, accountId, status, remark, QueryUtils.offset(map), QueryUtils.rows(map));
    }

    @Override
    public int insert(JSONObject obj, HttpServletRequest request) throws Exception {
        return chequeService.insertCheque(obj, request);
    }

    @Override
    public int update(JSONObject obj, HttpServletRequest request) throws Exception {
        return chequeService.updateCheque(obj, request);
    }

    @Override
    public int delete(Long id, HttpServletRequest request) throws Exception {
        return chequeService.deleteCheque(id, request);
    }

    @Override
    public int deleteBatch(String ids, HttpServletRequest request) throws Exception {
        return chequeService.batchDeleteCheque(ids, request);
    }

    @Override
    public int checkIsNameExist(Long id, String name) throws Exception {
        return chequeService.checkIsNameExist(id, name);
    }

}
